// ListCtrlColor.cpp : implementation file
//

#include "stdafx.h"
#include "moretunes.h"
#include "ListCtrlColor.h"
#include ".\listctrlcolor.h"
#include "album.h"

// CListCtrlColor

IMPLEMENT_DYNAMIC(CListCtrlColor, CListCtrl)
CListCtrlColor::CListCtrlColor()
: _track(-1)
, _listAlbum(0)
{
}

CListCtrlColor::~CListCtrlColor()
{
}


BEGIN_MESSAGE_MAP(CListCtrlColor, CListCtrl)
	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()



// CListCtrlColor message handlers


void CListCtrlColor::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) {
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
	int iRow;

	switch(lplvcd->nmcd.dwDrawStage)
	{
	case CDDS_PREPAINT:
		*pResult = CDRF_NOTIFYITEMDRAW;          // ask for item notifications.
		break;

	case CDDS_ITEMPREPAINT:
		*pResult = CDRF_DODEFAULT;

		iRow = (int) lplvcd->nmcd.dwItemSpec;
		if(iRow & 1)
		{
			lplvcd->clrTextBk = RGB(230, 230, 255);
			*pResult = CDRF_NEWFONT;
		}
		if (iRow == _track) {
			lplvcd->clrText = RGB(255, 0, 0);
			*pResult = CDRF_NEWFONT;
		}
		
		if (_listAlbum == TRUE) {
			Album *album;
			album = (Album*) this->GetItemData(iRow);
			if (album == NULL)
				break;
			if (album->_match == MATCH_AVERAGE)
				lplvcd->clrText = RGB(160, 160, 255);
			else if (album->_match == MATCH_OK)
				lplvcd->clrText = RGB(100, 100, 255);
			else if (album->_match == MATCH_GOOD)
				lplvcd->clrText = RGB(60, 60, 255);
			else if (album->_match == MATCH_PERFECT)
				lplvcd->clrText = RGB(0, 0, 255);
			else
				break;
			if (album->getAsin() == _proposal)
				lplvcd->clrTextBk = RGB(255, 190, 190);
			else
				lplvcd->clrTextBk = RGB(255, 210, 210);
			*pResult = CDRF_NEWFONT;
		}
		break;

	default:
		*pResult = CDRF_DODEFAULT;
	}
}
